desc "Runs tests on the primary platforms and configurations"
lane :test do
    verify(
        scheme: "FormValidatorSwift iOS"
    )
    verify(
        scheme: "FormValidatorSwift tvOS"
    )
    verify(
        scheme: "FormValidatorSwift macOS",
        destination: "platform=macOS"
    )
    verify(
        scheme: "iOS Example"
    )
    if is_ci?
        # Unable to run macOS UI Tests on Travis CI. See https://github.com/travis-ci/travis-ci/issues/7075
        build(
            scheme: "macOS Example",
            destination: "platform=macOS"
        )
    else
        verify(
            scheme: "macOS Example",
            destination: "platform=macOS"
        )
    end
    pod_lib_lint
end

desc "Runs tests"
lane :verify do |options|
    scheme = options[:scheme]
    destination = options[:destination]
    sdk = options[:sdk]
    output_directory = "fastlane/test_output/" + scheme + "/"
    opts = {
        :workspace => 'FormValidatorSwift.xcworkspace',
        :scheme => scheme,
        :destination => destination,
        :sdk => sdk,
        :code_coverage => true,
        :xcargs => "ONLY_ACTIVE_ARCH=YES",
        :output_directory => output_directory,
        :clean => true
    }
    scan(opts)
    upload_cov
end

desc "Builds scheme"
lane :build do |options|
    scheme = options[:scheme]
    destination = options[:destination]
    sdk = options[:sdk]
    xcodebuild(
        workspace: 'FormValidatorSwift.xcworkspace',
        scheme: scheme,
        destination: destination,
        sdk: sdk,
        xcargs: 'ONLY_ACTIVE_ARCH=YES',
        build: true,
        clean: true
    )
end

desc "Upload code coverage reports (if running on CI)"
lane :upload_cov do
    if is_ci?
        sh "bash ./codecov.sh"
    else
        say "No need to upload code coverage. Not running from CI."
    end
end
